package com.ea.eadp.nexus.test.pageDefinition.newconsole;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;


public class EnterTFACodePage extends ConsoleBasePage {
    public final static String twoFactorCodeInputBox = "twoFactorCode";

    public EnterTFACodePage(WebDriver driver) {
        super(driver, EnterTFACodePage.class, twoFactorCodeInputBox);
    }

    public void enterCode(String code) {
        log.info("Enter Code:" + code);
        sendInput(twoFactorCodeInputBox, code);
        clickBlank("//div[@id='panel-two-factor']//span[@class='title']");
        sendControllerKey('A');
    }

    public void resendCode() {
        sendControllerKey(Keys.DOWN);
        sendControllerKey('A');
    }
    public String getErrorMessage(){
        String message = "";

        // specific messages take priority over general message
        try {
            message = driver.findElement(By.xpath("//div[@id='modal']//h2[@class='title']")).getText();
        } catch (NoSuchElementException e) {
            // do nothing
        }

        try {
            message = driver.findElement(By.xpath("//div[@id='modal']//p[@class='description']")).getText();
        } catch (NoSuchElementException e) {
            // do nothing
        }

        return message;
    }
    public boolean getElementStatus(String elementId) {
        Boolean isabled=true;
        if (driver.findElement(By.id(elementId)).getAttribute("class").contains("disabled")||!driver.findElement(By.id(elementId)).isEnabled()){
            isabled=false;
        }
        return isabled;
    }
}
